import Vue from "vue";
import VueRouter from "vue-router";


import Login from "../views/login.vue";
import Doctor from "../views/doctorSystem.vue";
//引入电子病例的组件

import petsCenter from '../views/petsCenter/index.vue'
import petsCenterDetail from "../views/petsCenter/patient_detail.vue";

import address from '../views/address/index.vue'
import addressDetail from "../views/address/patient_detail.vue";

import register from "../views/register.vue";
import consumerSystem from "../views/userSystem.vue";
import notice from '../views/Notice.vue'
import homePage from '../views/homePage/index.vue'
import homePageDetail from '../views/homePage/detail.vue'


import Appointment from "../views/appointment/index.vue";
import AppointmentList from "../views/appointment/detail.vue";
import AppointmentList1 from "../views/appointment/detail1.vue";

import receivingOrders from "../views/receivingOrders/index.vue";
import receivingOrdersList from "../views/receivingOrders/detail.vue";

import questionAnswering from "../views/questionAnswering/index.vue";
import questionAnsweringDetail from "../views/questionAnswering/detail.vue";
import payDetail1 from "../views/pay/detail1.vue";
import userDetail1 from "../views/user/detail1.vue";
import answerDetail1 from "../views/answer/detail1.vue";
import questionAnsweringList from "../views/questionAnswering/list.vue";
import questionAnsweringDetail1 from "../views/questionAnswering/detail1.vue";


import MyUser from "../views/MyUser/index.vue";
import MyUserList from "../views/MyUser/list.vue";
// import MyUserList1 from "../views/MyUser/list1.vue";
import chat from "../views/chat/index.vue";
Vue.use(VueRouter);
import store from '@/store'
import pay from "@/views/pay/index.vue";
import user from "@/views/user/index.vue";
import answer from "@/views/answer/index.vue";
const routes = [{
    path: "/",
    redirect: "/login",
},
{
    path: "/login",
    name: "login",
    component: Login,
},
{
    path: "/chat",
    name: "chat",
    component: chat,
},
{
    path: "/admin",
    name: "doctor",
    component: Doctor,
    children: [
        {
            path: "homePage",
            component: homePage,
            redirect: "/admin/homePage/detail",
            children: [{
                    path: "detail",
                    component: homePageDetail,
                },
            
            ],
        },
        {
            path: "appointment",
            component: Appointment,
            redirect: "/admin/appointment/detail",
            children: [{
                    path: "detail",
                    component: AppointmentList1,
                },
            
            ],
        },
        {
            path: "questionAnswering",
            component: questionAnswering,
            redirect: "/admin/questionAnswering/detail",
            children: [{
                    path: "detail",
                    component: questionAnsweringDetail1,
                },
            ],
        },
        {
            path: "pay",
            component: pay,
            redirect: "/admin/pay/detail",
            children: [{
                path: "detail",
                component: payDetail1,
            },
            ],
        },
        {
            path: "answer",
            component: answer,
            redirect: "/admin/answer/detail",
            children: [{
                path: "detail",
                component: answerDetail1,
            },
            ],
        },
        {
            path: "user",
            component: user,
            redirect: "/admin/user/detail",
            children: [{
                path: "detail",
                component: userDetail1,
            },
            ],
        },
  
    ],
},
{
    path: "/consumer",
    name: "consumer",
    component: consumerSystem,
    redirect: "/consumer/homePage",
    children: [
        {
            path: "homePage",
            component: homePage,
            redirect: "/consumer/homePage/detail",
            children: [{
                    path: "detail",
                    component: homePageDetail,
                },
            
            ],
        },
        {
            path: "petsCenter",
            component: petsCenter,
            redirect: "/consumer/petsCenter/detail",
            children: [{
                    path: "detail",
                    component: petsCenterDetail,
                },
            
            ],
        },
        {
            path: "address",
            component: address,
            redirect: "/consumer/address/detail",
            children: [{
                    path: "detail",
                    component: addressDetail,
                },
            
            ],
        },
        {
            path: "appointment",
            component: Appointment,
            redirect: "/consumer/appointment/detail",
            children: [{
                    path: "detail",
                    component: AppointmentList,
                },
            ],
        },
        {
            path: "questionAnswering",
            component: questionAnswering,
            redirect: "/consumer/questionAnswering/detail",
            children: [{
                    path: "detail",
                    component: questionAnsweringDetail,
                },
                {
                    path: "list",
                    component: questionAnsweringList,
                },
            ],
        },
        {
            path: "receivingOrders",
            component: receivingOrders,
            redirect: "/consumer/receivingOrders/detail",
            children: [{
                    path: "detail",
                    component: receivingOrdersList,
                },
            ],
        },
        {
            path: "MyUser",
            component: MyUser,
            redirect: "/consumer/MyUser/detail",
            children: [{
                    path: "detail",
                    component: MyUserList,
                },
            ],
        },
    ],
},
{
    path: "/register",
    name: "register",
    component: register,
}
];

const router = new VueRouter({
    mode: "history",
    base: process.env.BASE_URL,
    routes,
});
const routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return routerPush.call(this, location).catch((error) => error);
};
const whiteList = ['/login', '/register']
router.beforeEach((to, from, next) => {
    // 检查前端路由 要to 的 path 是否需要进行权限认证,
    if (store.getters['user/getToken'] !== null && store.getters['user/getToken'] !== undefined) {
        next();
    }else {
        if (whiteList.indexOf(to.path) !== -1) {
        } else {
            
            next('/login');
        }
        next();
    }
});
export default router;